<template>
    <div class="fillInOrder">
      <div class="fillInOrder_header">
        <router-link tag="i" to="cart" class="iconfont icon-fanhui"></router-link>
        <span>填写订单</span>
      </div>
      <app-loading :isHidLoading="isHidLoading"></app-loading>
      <div class="fillInOrder_site">
        <div @click="selectSiteFn" v-if="site.length===0" class="select_address">
          <span>请选择收货地址</span>
          <i class="el-icon-arrow-right"></i>
        </div>
        <div @click="selectSiteFn" v-if="site" v-for="(val, index) in site" :key = index class="select_address">
          <p>{{val.receiver}}<span>{{val.telNumber}}</span></p>
          <span class="site">{{val.province}}{{val.city}}{{val.district}}{{val.details}}</span>
          <i class="el-icon-arrow-right"></i>
        </div>
        <div class="process_bar"></div>
      </div>
      <div class="fillInOrder_pay">
        <div>
          <span>支付方式</span>
          <div class="fillInOrder_pay_right">
            <span>在线支付</span>
            <img src="../assets/dot.png" alt="">
          </div>
        </div>
        <br>
        <div class="pay">
          <div class="pay_img">
            <img src="../assets/pay.png" alt="">
          </div>
          <div class="pay_title">
            <p>支付宝 <img src="../assets/tuijian.png" alt=""></p>
            <span>数亿用户都在用，安全可托付</span>
          </div>
          <input type="checkbox" id="comChe" :checked="alipayChe">
          <label for="comChe">
            <i class="el-icon-circle-check" @click="alipay"></i>
          </label>

        </div>
      </div>
      <div class="fillInOrderScroll" ref="fillInOrderScroll">
        <div>
          <div class="fill_box"></div>
          <div class="fillInOrder_commodity" v-for="(item, key) in fillIn" :key = key>
            <div class="com_img">
              <img :src="item.pid.prodImage[2]" alt="">
            </div>
            <div class="com_title">
              <p class="con_sup_title">{{item.pid.prodSubTitle}}</p>
              <span class="con_sub_title">{{item.pid.prodSupTitle}}</span>
              <p class="com_money">￥<span>{{item.pid.currentPrice}}*{{item.num}}</span></p>
              <span class="com_server">支持两小时极速达</span>
            </div>
          </div>
          <div class="up_box"></div>
        </div>
      </div>
      <div class="fillInOrder_submit">
        <span class="com_money">￥<span>{{Number(price).toFixed(2)}}</span></span>
        <button :class="{'active':alipayCheAcitve}" @click="playFn">提交订单</button>
      </div>
      <!--弹框-->
      <message :message.sync="messageShow">
        <span>{{messageTitle}}</span>
      </message>
    </div>
</template>

<script>
    export default {
        name: "fillInOrder",
        data(){
          return{
            fillIn:null,
            site:[],
            alipayChe:false,
            alipayCheAcitve:false,
            isHidLoading:false,
            messageTitle:'请选择支付方式^_^',
            order:null,
            play:null,
            url:null,
            messageShow:false
          }
        },
        created(){
          this.$store.state.fillIn||this.$router.push({name:'cart'});
          this.$store.state.fillIn&&(this.fillIn = this.$store.state.fillIn);
          this.$store.state.site&&(this.site.push(this.$store.state.site));
          this.$store.state.order&&(this.order = this.$store.state.order);
        },
        mounted(){
          this.$nextTick(()=>{
            this.$refs.fillInOrderScroll&&new this.$BSscroll(this.$refs.fillInOrderScroll,{
              //动画移动方向
              scrollY:true,
              //弹跳的方向
              bounce:{
                left:false,
                right:false,
                top:false,
                bottom:true
              },
              //动画速率
              momentum:true,
              click:true,
            })
          })
        },
        computed:{
          price(){
           return this.fillIn&&this.fillIn.reduce((prev, item)=> prev+=item.pid.currentPrice*item.num,0)
          }
        },
        methods:{
          alipay(){
            this.alipayChe = !this.alipayChe;
            if(!this.alipayChe){
              this.alipayCheAcitve=false;
            }
            if(this.alipayChe&&this.order){
              this.isHidLoading = true;
              this.$http.post('/api/accounts',{orderid:this.order}).then(req=>{
                if(req.data.code===1){
                  this.url = req.data.data.pay_url;
                  this.alipayCheAcitve=true;
                  this.isHidLoading = false;
                }
              })
            }
          },
          playFn(){
            if(this.site.length===0){
              this.messageTitle = '请填写收货地址^_^';
              this.messageShow = true;
              return;
            }
            if(!this.alipayChe){
              this.messageTitle='请选择支付方式^_^';
              this.messageShow = true;
              return;
            }
            window.location.href = this.url;
          },
          //选择地址
          selectSiteFn(){
            this.$store.state.sitefill=this.order;
            this.$router.push({name:'myAddress',params:{siteid:this.order}});
          }
        }
    }
</script>

<style scoped>
  .fillInOrder{
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    background: #fafafa;
    box-sizing: border-box;
    padding: 0 22px;
  }
  .fillInOrder_header{
    width: 100%;
    height: 80px;
    box-sizing: border-box;
    padding: 0 18px;
    text-align: center;
    line-height: 80px;
    color: #333333;
  }
  .fillInOrder_header>i{
    font-size: 42px;
    float: left;
  }
  .fillInOrder_header>span{
    font-size: 34px;
  }
  .fillInOrder_site,.fillInOrder_pay,.fillInOrder_commodity,.fillInOrder_submit{
    width: 100%;
    box-sizing: border-box;
    margin-top: 22px;
    padding: 0 22px;
    box-shadow: 1px 1px 10px 1px #ececec;
    background: white;
  }
  .fillInOrder_site{
    position: relative;
    padding-top: 20px;
  }
  .fillInOrder_site>p{
    font-size: 36px;
    font-weight: bold;
    color: #333333;
  }
  .process_bar{
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: inline-block;
    width: 100%;
    height: 8px;
    border-radius: inherit;
    transition: width .2s ease-in-out;

    background: #fbfbfb repeating-linear-gradient(135deg,
    rgb(255,255,255) 0px,
    rgba(255,255,255,1) 25px,
    rgb(71,238,20) 25px,
    rgba(71,238,20,1) 50px,
    rgb(255,255,255) 50px,
    rgba(255,0,0,0) 75px,
    rgb(202,22,11) 75px,
    rgba(202,22,11,1) 100px
    );
  }
  .select_address{
    padding: 0 ;
  }
  .select_address>i{
    font-size: 42px;
    float: right;
    font-weight: 900;
    margin-top: 40px;
    color: #333333;
  }
  .select_address>span{
    color: #7f7f7f;
    font-size: 34px;
    line-height: 130px;
    display: inline-block;
    text-align: center;
    margin-bottom: 30px;
  }
  .select_address>p{
    text-align: left;
    margin-top: 10px;
    font-size: 36px;
    font-weight: bold;
    color: #333333;
  }
  .select_address>p>span{
    margin-left: 25px;
  }
  .select_address>.site{
    text-align: right;
  }
  .fillInOrder_pay{
    position: relative;
    padding: 15px 22px;
  }
  .fillInOrder_pay div{
    display: inline-block;
    vertical-align: middle;
  }
  .fillInOrder_pay>div>span{
    font-size: 32px;
    line-height: 65px;
    vertical-align: middle;
  }
  .fillInOrder_pay_right{
    font-weight: bold;
    font-size: 32px;
    position: absolute;
    top:15px;
    right: 20px;
  }
  .fillInOrder_pay_right>img{
    width: 70px;
    vertical-align: middle;
  }
  .pay_img>img{
    width: 80px;
    height: 80px;
    vertical-align: middle;
  }
  .pay_title{
    margin-left: 20px;
    vertical-align: middle;
  }
  .pay_title>p{
    font-family: 华文细黑;
    font-weight: bold;
    font-size: 32px;
    color: #333333;
  }
  .pay_title>p>img{
    width: 70px;
  }
  .pay_title>span{
    font-size: 24px;
    color: #7f7f7f;
  }
  .pay>input{
    display: none;
  }
  .pay>input[type='checkbox']:checked+label>i{
    color: #4ae03a;
  }
  .pay>label>i{
    font-size: 50px;
    color: #d3d3d3;
    position: absolute;
    top:100px;
    right: 30px;
  }
  .fillInOrderScroll{
    height: 70vh;
    overflow: hidden;
  }
  .fill_box{
    height: 5px;
  }
  .up_box{
    height: 200px;
  }
  .fillInOrder_commodity{
    padding:  30px 20px;
  }
  .fillInOrder_commodity>div{
    display: inline-block;
    font-size: 0;
  }
  .com_img,.com_title{
    vertical-align: middle;
  }
  .com_img{
    width: 30%;
    text-align: center;
  }
  .com_title{
    width: 65%;
  }
  .com_img>img{
    margin: auto;
    max-width: 185px;
    max-height: 220px;
  }
  .con_sup_title,.con_sub_title{
    overflow : hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp:1;
    -webkit-box-orient: vertical;
  }
  .con_sup_title{
    font-family: 华文细黑;
    font-weight: bold;
    color: #333333;
    font-size: 32px;
  }
  .con_sub_title{
    font-family: 华文细黑;
    font-size: 28px;
    color: #4e4e4e;
    margin: 10px 0;
  }
  .com_money{
    font-size: 38px;
    color: #4ae03a;
  }
  .com_money>span{
    font-family: 华文细黑;
    font-size: 36px;
    font-weight: bold;
  }
  .com_server{
    display: inline-block;
    margin-top: 10px;
    padding: 0 30px;
    font-size: 28px;
    border-radius: 30px;
    border: 2px solid #e99892;
    color: #e99da2;
  }
  .fillInOrder_submit{
    padding-left: 20px;
    padding-right: 0;
    width: 100vw;
    position: fixed;
    right: 0;
    left: 0;
    bottom: 0;
    height: 100px;

  }
  .fillInOrder_submit>.active{
    background: linear-gradient(to left,#31e07c,#1cd245);
  }
  .fillInOrder_submit>button{
    background: #95d894;
    color: white;
    height: 100%;
    width: 30%;
    text-decoration: none;
    font-size: 34px;
    text-align: center;
    line-height: 100px;
    float: right;
    outline: none;
    border: none;
  }
  .fillInOrder_submit>span{
    line-height: 100px;
  }
  .fillInOrder_submit>span>span{
    font-size: 40px;
  }
</style>
